package com.taoyun.web.controller;

import com.taoyun.pojo.entity.User;
import com.taoyun.service.IUserService;
import com.taoyun.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 *  controller示例
 *
 * @author FengJingdong
 */
@RestController
public class HelloController {

    @Autowired
    private IUserService userService;

    /**
     *  查找用户
     *
     * @param id 要查找的用户id
     * @return
     */
    @GetMapping("taoyun/v1/user")
    public Response findUsers(Integer id){
        User users = userService.findUser(id);
        return Response.success(users);
    }

    /**
     * 批量删除用户
     *
     * @param ids 要删除的多个id，以逗号分隔
     * @return
     */
    @GetMapping("taoyun/v1/deleteUsers/{ids}")
    public Response deleteUsers(@PathVariable  String ids){
        // String 转成 List<Integer>
        List<Integer> collect = Arrays.stream(ids.split(","))
                .map(Integer::valueOf)
                .collect(Collectors.toList());

//        userService.deleteUser(collect);
        return Response.success();
    }

    @RequestMapping("/hello")
    public String Hello(){
        return "Hello,taoyun";
    }
}
